package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.PhyAppointBean;

import java.util.List;


public class ReportAdapter extends RecyclerView.Adapter<ReportAdapter.MyViewHolder> {

    Context context;
    List<PhyAppointBean.CheckUp> list;
    OnItemClickListen onItemClickListen;
    public ReportAdapter(Context context , List<PhyAppointBean.CheckUp> list,OnItemClickListen onItemClickListen){
        this.context=context;
        this.list=list;
        this.onItemClickListen=onItemClickListen;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View inflate = LayoutInflater.from(context).inflate(R.layout.item_report, null, false);

        return new MyViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        holder.nameTv.setText(list.get(position).getName());
        if ("0".equals(list.get(position).getSex().trim())){ //女
            holder.sexTv.setText("女");
        }else if ("1".equals(list.get(position).getSex().trim())){ //男
            holder.sexTv.setText("男");
        }
        holder.checkIdTv.setText(list.get(position).getCheckupid());
        holder.lookAppoint.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListen.onItemClicks(list.get(position).getCheckupid());
            }
        });
    }

    public void addData(List<PhyAppointBean.CheckUp> list){

        this.list=list;
        this.notifyDataSetChanged();
    }
    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView nameTv; //姓名
        TextView sexTv;  //性别
        TextView checkIdTv; //流水号
        TextView lookAppoint; //查看报告

        public MyViewHolder(View itemView) {
            super(itemView);
            nameTv=itemView.findViewById(R.id.nameTv);
            sexTv=itemView.findViewById(R.id.sexTv);
            checkIdTv=itemView.findViewById(R.id.checkIdTv);
            lookAppoint=itemView.findViewById(R.id.lookAppoint);
        }
    }

    public interface  OnItemClickListen{

        void onItemClicks(String checkId);
    }
}
